home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet 2002 February / Practical Internet February 2002.iso / pc / Software / Browsing / httrack-3.09e2.exe / {app} / src / htscore.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-07  |  11.0 KB  |  357 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Main file .h                                           */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38. #ifndef HTTRACK_DEFH
  39. #define HTTRACK_DEFH
  40.  
  41.  
  42. #include "htsglobal.h"
  43.  
  44. /* specific definitions */
  45. #include "htsbase.h"
  46. // Includes & dΘfinitions
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50. #include <sys/types.h>
  51. #include <sys/stat.h>
  52. #ifdef _WIN32
  53. #include <conio.h>
  54. #include <signal.h>
  55. #include <direct.h>
  56. #else
  57. #include <signal.h>
  58. #include <unistd.h>
  59. #endif
  60. /* END specific definitions */
  61.  
  62.  
  63. // Include htslib.h for all types
  64. #include "htslib.h"
  65.  
  66. #include "htsopt.h"
  67.  
  68. // structure d'un lien
  69. typedef struct {
  70.   char firstblock;      // flag 1=premier malloc 
  71.   char link_import;     // lien importΘ α la suite d'un moved - ne pas appliquer les rΦgles classiques up/down
  72.   short int depth;      // profondeur autorisΘe lien ; >0 forte 0=faible
  73.   short int pass2;      // traiter aprΦs les autres, seconde passe. si == -1, lien traitΘ en background
  74.   int premier;          // pointeur sur le premier lien qui a donnΘ lieu aux autres liens du domaine
  75.   int precedent;        // pointeur sur le lien qui a donnΘ lieu α ce lien prΘcis
  76.   //int moved;            // pointeur sur moved
  77.   short int retry;      // nombre de retry restants
  78.   short int testmode;   // mode test uniquement, envoyer juste un head!
  79.   char* adr;            // adresse
  80.   char* fil;            // nom du fichier distant
  81.   char* sav;            // nom α sauver sur disque (avec chemin Θventuel)
  82.   char* cod;            // chemin codebase Θventuel si classe java
  83.   char* former_adr;     // adresse initiale (avant Θventuel moved), peut Ωtre nulle
  84.   char* former_fil;     // nom du fichier distant initial (avant Θventuel moved), peut Ωtre nul
  85.   // pour optimisation:
  86. #if HTS_HASH
  87.   int hash_next[3];     // prochain lien avec mΩme valeur hash
  88. #else
  89.   int sav_len;          // taille de sav
  90. #endif
  91. } lien_url;
  92.  
  93. // chargement de fichiers en 'arriΦre plan'
  94. typedef struct {
  95. #if DEBUG_CHECKINT
  96.   char magic;
  97. #endif
  98.   char url_adr[HTS_URLMAXSIZE*2];     // adresse
  99.   char url_fil[HTS_URLMAXSIZE*2];     // nom du fichier distant
  100.   char url_sav[HTS_URLMAXSIZE*2];     // nom α sauver sur disque (avec chemin Θventuel)
  101.   char referer_adr[HTS_URLMAXSIZE*2]; // adresse host page referer
  102.   char referer_fil[HTS_URLMAXSIZE*2]; // fichier page referer
  103.   char location_buffer[HTS_URLMAXSIZE*2];  // "location" en cas de "moved" (302,..)
  104.   char tmpfile[HTS_URLMAXSIZE*2];     // nom α sauver temporairement (compressΘ)
  105.   char send_too[1024];    // donnΘes α envoyer en mΩme temps que le header
  106.   int status;           // status (-1=non utilisΘ, 0: prΩt, >0: opΘration en cours)
  107.   int testmode;         // mode de test
  108.   int timeout;            // gΘrer des timeouts? (!=0  : nombre de secondes)
  109.   TStamp timeout_refresh; // si oui, time refresh
  110.   int rateout;            // timeout refresh? (!=0 : taux minimum tolΘrΘ en octets/s)
  111.   TStamp rateout_time;    // si oui, date de dΘpart
  112.   LLint maxfile_nonhtml;  // taille max d'un fichier non html
  113.   LLint maxfile_html;     // idem pour un ficheir html
  114.   htsblk r;               // structure htsblk de chaque objet en background 
  115.   short int is_update;    // mode update
  116.   int head_request;       // requΦte HEAD?
  117.   LLint range_req_size;   // range utilisΘ
  118.   //
  119.   int http11;             // L'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  120.   int is_chunk;           // chunk?
  121.   char* chunk_adr;        // adresse chunk en cours de chargement
  122.   LLint chunk_size;       // taille chunk en cours de chargement
  123.   LLint compressed_size;  // taille compressΘs (stats uniquement)
  124.   //
  125.   short int* pass2_ptr;   // pointeur sur liens[ptr]->pass2
  126.   //
  127.   char info[256];       // Θventuel status pour le ftp
  128.   int stop_ftp;         // flag stop pour ftp
  129. #if DEBUG_CHECKINT
  130.   char magic2;
  131. #endif
  132. } lien_back;
  133.  
  134. // cache
  135. typedef struct {
  136.   int version;        // 0 ou 1
  137.   /* */
  138.   int type;
  139.   FILE *dat,*ndx,*olddat;
  140.   char *use;      // liste des adr+fil
  141.   FILE *lst;      // liste des fichiers pour la "purge"
  142.   char lastmodified[256];
  143.   // HASH
  144.   void* hashtable;
  145.   // fichiers log optionnels
  146.   FILE* log;
  147.   FILE* errlog;
  148.   // variables
  149.   int ptr_ant;      // pointeur pour anticiper
  150.   int ptr_last;     // pointeur pour anticiper
  151. } cache_back;
  152.  
  153. typedef struct {
  154.   lien_url** liens;                     // pointeur sur liens
  155.   int max_lien;                         // indice le plus grand rencontrΘ
  156.   int hash[3][HTS_HASH_SIZE];           // tables pour sav/adr-fil/former_adr-former_fil
  157. } hash_struct;
  158.  
  159. #if HTS_HASH
  160. #else
  161. #define hash_write(A,B)
  162. #endif
  163.  
  164. typedef struct {
  165.   FILE* lst;
  166.   char path[HTS_URLMAXSIZE*2];
  167. } filecreate_params;
  168.  
  169. // Fonctions
  170.  
  171. // INCLUDES .H PARTIES DE CODE HTTRACK
  172.  
  173. // routine main
  174. #include "htscoremain.h"
  175.  
  176. // divers outils pour httrack.c
  177. #include "htstools.h"
  178.  
  179. // aide pour la version en ligne de commande
  180. #include "htshelp.h"
  181.  
  182. // gΘnΘration du nom de fichier α sauver
  183. #include "htsname.h"
  184.  
  185. // gestion ftp
  186. #include "htsftp.h"
  187.  
  188. // routine parser java
  189. #include "htsjava.h"
  190.  
  191. // gestion interception d'URL
  192. #include "htscatchurl.h"
  193.  
  194. // gestion robots.txt
  195. #include "htsrobots.h"
  196.  
  197. // routines d'acceptation de liens
  198. #include "htswizard.h"
  199.  
  200. // routines de regexp
  201. #include "htsfilters.h"
  202.  
  203. // gestion backing
  204. #include "htsback.h"
  205.  
  206. // gestion cache
  207. #include "htscache.h"
  208.  
  209. // gestion hashage
  210. #include "htshash.h"
  211.  
  212. // infos console
  213. #if HTS_ANALYSTE_CONSOLE
  214. #include "httrack.h"
  215. #endif
  216.  
  217. #include "htsdefines.h"
  218.  
  219. #include "hts-indextmpl.h"
  220.  
  221. // INCLUDES .H PARTIES DE CODE HTTRACK
  222.  
  223. //
  224.  
  225. /*
  226. typedef void  (* t_hts_htmlcheck_init)(void);
  227. typedef void  (* t_hts_htmlcheck_uninit)(void);
  228. typedef int   (* t_hts_htmlcheck_start)(httrackp* opt);
  229. typedef int   (* t_hts_htmlcheck_end)(void);
  230. typedef int   (* t_hts_htmlcheck_chopt)(httrackp* opt);
  231. typedef int   (* t_hts_htmlcheck)(char* html,int len,char* url_adresse,char* url_fichier);
  232. typedef char* (* t_hts_htmlcheck_query)(char* question);
  233. typedef char* (* t_hts_htmlcheck_query2)(char* question);
  234. typedef char* (* t_hts_htmlcheck_query3)(char* question);
  235. typedef int   (* t_hts_htmlcheck_loop)(lien_back* back,int back_max,int back_index,int lien_tot,int lien_ntot,LLint stat_bytes,LLint stat_bytes_recv,int stat_time,int stat_nsocket, LLint stat_written, int stat_updated, int stat_errors, int irate, int nbk );
  236. typedef int   (* t_hts_htmlcheck_check)(char* adr,char* fil,int status);
  237. typedef void  (* t_hts_htmlcheck_pause)(char* lockfile);
  238. */
  239.  
  240. // demande d'interaction avec le shell
  241. #if HTS_ANALYSTE
  242. //char HTbuff[1024];
  243. /*
  244. extern t_hts_htmlcheck_init    hts_htmlcheck_init;
  245. extern t_hts_htmlcheck_uninit  hts_htmlcheck_uninit;
  246. extern t_hts_htmlcheck_start   hts_htmlcheck_start;
  247. extern t_hts_htmlcheck_end     hts_htmlcheck_end;
  248. extern t_hts_htmlcheck_chopt   hts_htmlcheck_chopt;
  249. extern t_hts_htmlcheck         hts_htmlcheck;
  250. extern t_hts_htmlcheck_query   hts_htmlcheck_query;
  251. extern t_hts_htmlcheck_query2  hts_htmlcheck_query2;
  252. extern t_hts_htmlcheck_query3  hts_htmlcheck_query3;
  253. extern t_hts_htmlcheck_loop    hts_htmlcheck_loop;
  254. extern t_hts_htmlcheck_check   hts_htmlcheck_check;
  255. extern t_hts_htmlcheck_pause   hts_htmlcheck_pause;
  256. */
  257. //
  258. int hts_is_parsing(int flag);
  259. int hts_is_testing(void);
  260. int hts_setopt(httrackp* opt);
  261. int hts_addurl(char** url);
  262. int hts_resetaddurl(void);
  263. int copy_htsopt(httrackp* from,httrackp* to);
  264. char* hts_errmsg(void);
  265. int hts_setpause(int);      // pause transfer
  266. int hts_request_stop(int force);
  267. //
  268. char* hts_cancel_file(char * s);
  269. void hts_cancel_test(void);
  270. void hts_cancel_parsing(void);
  271. //
  272. // Variables globales
  273. extern int _hts_in_html_parsing;
  274. extern int _hts_in_html_done;  // % rΘalisΘs
  275. extern int _hts_in_html_poll;  // parsing
  276. extern char _hts_errmsg[1100];
  277. extern int _hts_setpause;
  278. //extern httrackp* _hts_setopt;
  279. extern char** _hts_addurl;
  280. extern int _hts_cancel;
  281. #endif
  282.  
  283.  
  284.  
  285. //
  286.  
  287.  
  288. //int httpmirror(char* url,int level,httrackp opt);
  289. int httpmirror(char* url1,httrackp opt);
  290. int filesave(char* adr,int len,char* s);
  291. int engine_stats(void);
  292. void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,lien_back* back,int back_max,char** filters,int filter_max,int* filptr,char* host);
  293. FILE* filecreate(char* s);
  294. int filenote(char* s,filecreate_params* params);
  295. HTS_INLINE void usercommand(int exe,char* cmd,char* file);
  296. void usercommand_exe(char* cmd,char* file);
  297. char* structcheck_init(int init);
  298. int structcheck(char* s);
  299. HTS_INLINE int fspc(FILE* fp,char* type);
  300. char* next_token(char* p,int flag);
  301. //
  302. char* readfile(char* fil);
  303. char* readfile_or(char* fil,char* defaultdata);
  304. #if 0
  305. void check_rate(TStamp stat_timestart,int maxrate);
  306. #endif
  307.  
  308. // liens
  309. int liens_record(char* adr,char* fil,char* save,char* former_adr,char* former_fil,char* codebase);
  310.  
  311.  
  312. // backing, routines externes
  313. int back_fill(lien_back* back,int back_max,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  314. int backlinks_done(lien_url** liens,int lien_tot,int ptr);
  315. int back_fillmax(lien_back* back,int back_max,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  316.  
  317. // cancel file
  318. #if HTS_ANALYSTE
  319. char* hts_cancel_file(char * s);
  320. void hts_cancel_test(void);
  321. void hts_cancel_parsing(void);
  322. #endif
  323.  
  324. int ask_continue(void);
  325. int nombre_digit(int n);
  326.  
  327. // Java
  328. int hts_add_file(char* file,int file_position);
  329.  
  330. // Polling
  331. #if HTS_POLL
  332. HTS_INLINE int check_flot(T_SOC s);
  333. HTS_INLINE int check_stdin(void);
  334. int read_stdin(char* s,int max);
  335. #endif
  336.  
  337. httrackp* hts_declareoptbuffer(httrackp* optdecl);
  338. void sig_finish( int code );     // finir et quitter
  339. void sig_term( int code );       // quitter
  340. #if HTS_WIN
  341. void sig_ask( int code );        // demander
  342. #else
  343. void sig_back( int code );       // ignorer et mettre en backing 
  344. void sig_ask( int code );        // demander
  345. void sig_ignore( int code );     // ignorer signal
  346. void sig_doback(int);            // mettre en arriΦre plan
  347. #endif
  348.  
  349. // Void
  350. void voidf(void);
  351.  
  352. #define HTS_TOPINDEX "TOP_INDEX_HTTRACK"
  353.  
  354. #endif
  355.  
  356.  
  357.